#include "../h/QuantityObject.h"
#include "../h/ObjectsContainer.h"
#include "../h/DateList.h"
#include "../h/Event.h"
#include "Events.h"
#include "AppLogger.h"
#include "Reading.h"
#include <string>
#include <iostream.h>
#include "../h/Bank.h"
#include "User.h"
#include "Poco/DateTime.h"
#include "Poco/DateTimeParser.h"
#include <sstream>
#include "SimulationWorkFlow.h"
using namespace std;
using namespace Poco;


int main(int argc, char** argv)
{

	Reading* readerFromConfig =0;//("config.ini");
	Reading* readerFromEvents=0;//("noDealNoMoney.ini");
	try
	{
		readerFromConfig = new Reading(argv[1]);
		CAppLogger::Instance().setPriority(readerFromConfig -> getLoggerConsolePriority(),
					readerFromConfig -> getLoggerFilePriority());
	}
	catch (OpenFileException e)
	{
		readerFromConfig = new Reading();
		CAppLogger::Instance().setPriority(6,5);
		CAppLogger::Instance().Log("Error configuaration file not found",Message::PRIO_CRITICAL);
	}

	try
	{
		readerFromEvents = new Reading(argv[2]);
	}
	catch (OpenFileException e)
	{
		readerFromConfig = new Reading();
		CAppLogger::Instance().Log("Error events file not found",Message::PRIO_CRITICAL);
	}

//	CAppLogger::Instance().setPriority(readerFromConfig.getLoggerConsolePriority(),
//			readerFromConfig.getLoggerFilePriority());
//	//CAppLogger::Instance().Log("testing",Message::PRIO_CRITICAL);
//	bool sayaOn = readerFromConfig -> getSayaON();
	Bank* bank = new Bank();
	double money = readerFromConfig -> getUserAcount();
    User* eAlon =new User("eAlon","13",bank,money);
    User* eCherny =new User("eCherny","19",bank,money);
    User* eGorovoy =new User("eGorovoy","22",bank,money);
    User* eGutman =new User("eGutman","32",bank,money);
    User* eKatz =new User("eKatz","51",bank,money);
    User* ePoster =new User("ePoster","59",bank,money);
    User* eSaya =new User("eSaya","62",bank,money);
    User* eSoref =new User("eSoref","75",bank,money);
    User* eToman =new User("eToman","88",bank,money);
    User* eWeis =new User("eWeis","95",bank,money);
    User* eZolotowski =new User("eZolotowski","99",bank,money);
    vector<User*> users;
    users.push_back(eAlon);
    users.push_back(eCherny);
    users.push_back(eGorovoy);
    users.push_back(eGutman);
    users.push_back(eKatz);
    users.push_back(ePoster);
    users.push_back(eSaya);
    users.push_back(eSoref);
    users.push_back(eToman);
    users.push_back(eWeis);
    users.push_back(eZolotowski);
    Events events = Events();
    vector<Event*> e = readerFromEvents->getAllTheEvents();
    vector<Event*>::iterator it;
    for(it = e.begin();it<e.end();it++)
    {
    	Event* event = *it;
    	events.addEvent(event);
    }
    SimulationWorkFlow sim = SimulationWorkFlow(users,&events,readerFromConfig->getSayaON(),
    		readerFromConfig->getSayaBuing(),argv[1],argv[2],
    		readerFromConfig->getEnergyValue());
    sim.run();

    vector<User*>::iterator userIterator;
    for (userIterator = users.begin();userIterator< users.end();)
    {
    	delete (*userIterator);
    	users.erase(userIterator);
    }
    delete (bank);
    delete (readerFromConfig);
    delete (readerFromEvents);




}
